<?php
require_once "Common/database.php";
require_once "Common/values.php";
if($_POST[select]=='' AND $_GET[f2]!='')
{
$_POST['select']=$_GET['f2'];
}
$user1='%'.$user.'%';
$result = mysql_query("SELECT * FROM `tblSelect` WHERE `User`LIKE '$user1' OR User='all'");


if($_POST['select']=='')
{

$_POST[select]='Custom';
$_POST[project]='%';
$_POST[operator]='%';
$_POST[line]='%';
$_POST[department]='%';
$_POST[branch]='%';
$_POST[private1]='%';
$active='Custom';

}

while($row = mysql_fetch_array($result))
{
if($active!='Custom')
{
if($row[Select]=='my' && $_POST[select]=='my')
{

$_POST[lognumber]=$row[LogNumber];
#$_POST[operator]=$row['Operator'];
if ($row[Assigned]=='$user')
    {
    $_POST[assigned]=$user;    
    }
else
    {
    $_POST[assigned]=$row[Assigned];    
    }

$_POST[requestor]=$row[Requestor];
$_POST[subject]=$row[Subject];
$_POST[proirty]=$row[Proirty];
$_POST[status]=$row[Status];
$_POST[closed]=$row[Closed];
$_POST[project]=$row[Project];
$_POST[due]=$row[Due];
$_POST[line]=$row[Line];
$_POST[department]=$row[Department];
$_POST[branch]=$row[Branch];
$_POST[Private1]=$row["Private"];
$active=$row[Select];

}
else
{

if($row[Select]==$_POST[select])
{


$_POST[lognumber]=$row[LogNumber];
#$_POST[operator]=$row['Operator'];
$_POST[assigned]=$row[Assigned];
$_POST[requestor]=$row[Requestor];
$_POST[subject]=$row[Subject];
$_POST[proirty]=$row[Proirty];
$_POST[status]=$row[Status];
$_POST[closed]=$row[Closed];
$_POST[project]=$row[Project];
$_POST[due]=$row[Due];
$_POST[line]=$row[Line];
$_POST[department]=$row[Department];
$_POST[branch]=$row[Branch];
$_POST[private1]=$row["Private"];
$active=$row[Select];
}
}
}
}



switch ($_POST[closed])
{
case ("Closed");
$_POST[closed]='checked';
	break;
case ("Open");
$_POST[closed]='';
	break;
case ("");
$_POST[closed]='';
	break;
}
echo '<P><h3>All Jobs ('.$_POST[select].')</h3>';
echo '<center><table><tr>';
echo '<FORM action="index.php?m=h&p=hfilter&f=helpdesk" method="POST"><td style="border:0px solid ;" valign="top"><select name=select onchange="this.form.submit();"><option>'.$_POST[select].'</option>';
genSelect();
echo '</select></td><td class="noborder"></form></td>';
echo '<FORM action="index.php?p=hsearch&f=helpesk" method="POST"><td style="border:0px solid;" valign="top">';
echo 'Log:<INPUT type="text" name="logsearch" size="10" maxlength="10"></td> ';
echo ' <td class="noborder"><INPUT type="image" src="img/go.gif">
</FORM></td>';
echo '</tr></table><center>';
require 'Common/dashboard2.php';
echo '<br>';
colourkey();
$query="SELECT * FROM tblJobs WHERE status LIKE '$_POST[status]' AND LogNumber LIKE '$_POST[lognumber]' AND Requestor LIKE '$_POST[requestor]' AND Subject LIKE '$_POST[subject]' AND Proirty LIKE '$_POST[proirty]' AND Closed LIKE '$_POST[closed]' AND Assigned LIKE '$_POST[assigned]' AND Line LIKE '$_POST[line]' AND Project LIKE '$_POST[project]' AND Due LIKE '$_POST[due]' AND Branch LIKE '$_POST[branch]' AND Department LIKE '$_POST[department]' AND `Private` LIKE '$_POST[private1]'";
$result = mysql_query($query);

echo '<b>',mysql_affected_rows(),' Records found</b>';


echo '<FORM action="index.php?m=h&p=hfilter&f=helpdesk" method="POST">';
echo '<TABLE width="100%" valign="top" Border=1 >';
echo '<tr bgcolor="'.$colourtoprow.'"><td>Log Number</td><td>Due
</td><td>Assigned <br>to</td><td>Requestor</td><td>Subject</td><td>Proirty</td><td></td><td>Status</td><td>O/C</td></tr>';
echo '<tr><td><input type=text name=lognumber value='.$_POST[lognumber].'></td><td><INPUT type="text" size="8"name="due" value="'.$_POST[due].'">';
echo '</td>';
echo '<td><SELECT name="assigned">';
echo '<option>'.$_POST[assigned].'</option><option> </option>';
echo '<option>%</option>';
echo '<option>Not Assigned</option>';
genOperator();
echo '</select></td>';
echo '<td><input type=text name=requestor value='.$_POST[requestor].'>';
echo ' </td><td><input type=text name=subject value="'.$_POST[subject].'"></td><td><select name=proirty><option>'.$_POST[proirty].'</option>';
echo '<option></option>';
echo '<option>%</option>';
genProirty();
echo '</td>';
echo '<td></td><INPUT type="hidden" name="line"><td><select name=status><option>'.$_POST[status].'</option><option></option><option>%</option>';
genStatus();
echo '</td><td><select name="closed">';
if($_POST[closed]=='checked')
{
$_POST[closed]='Closed';
}
else
{
if($_POST[closed]=='%')
{
$_POST[closed]='All (%)';
}
else 
{
$_POST[closed]='Open';
}
}
echo '<option>'.$_POST[closed].'</option><option></option>';
echo '<option>Open</option><option>Closed</option><option>%</option>';
echo '</td><td><INPUT type="submit" value="Go"></td></tr>';
while($row = mysql_fetch_array($result))
  {
   if($row[Closed]=='checked')
{
$row[Closed]='Closed';
}
else
{
$row[Closed]='Open';
}
  echo '
<tr ';
colourjobs();
echo 'id="row'.$i.'" onMouseOver="row'.$i.'.style.backgroundColor=\''.$colourselector.'\';" onmouseout="row'.$i.'.style.backgroundColor=\''.$colour.'\';" onclick="location.href=\'index.php?f=helpdesk&p=hupdate&log='.$row['LogNumber'] .' \'">
<td>'.$row['LogNumber']. "</td><td>" . $row['Due'].'</td>'.'<td>'.$row[Assigned].'</td><td>'.$row['Requestor'].'</td><td>'.$row[Subject].'</td>'.'<td>'.$row[Proirty].'</td>'.'<td>'.'</td>'.'<td>'.$row[Status].'</td>'.'<td>'.$row[Closed].'</td></tr>';
  $i=$i+1;
  }
echo '</TABLE> </FORM>';
mysql_close();
?>